package cn.myschool.java79.test;

import cn.myschool.java79.dao.SubjectMapper;
import cn.myschool.java79.entity.Subject;
import cn.myschool.java79.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

/**
 * @author oldliu
 * @since 1.0
 */
public class AddSubject {
    public static void main(String[] args) {
        SqlSession s= MybatisUtil.get();
        Subject subject=new Subject();
        subject.setSubjectname("科学养鲸鱼");
        subject.setClasshour(100);
        subject.setGradeid(3);
        System.out.println(subject);
        try {
            SubjectMapper mapper = s.getMapper(SubjectMapper.class);
            int add = mapper.add(subject);
            System.out.println("加入了" + add + "门新课，新课的主键是："+subject.getId());
        }finally {
            MybatisUtil.close(s);
        }

    }
}
